package com.wz.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: WZ
 * @create: 2018-07-20 14:31
 **/
@RestController
public class ComputController {

    @Autowired
    DiscoveryClient discoveryClient;

    @RequestMapping("/add")
    private Integer add(@RequestParam Integer a ,@RequestParam Integer b){

        List<ServiceInstance> instances = discoveryClient.getInstances("STORES");
        System.out.println("ServiceInstance size "+instances.size());
        for (String s: discoveryClient.getServices()) {
            List<ServiceInstance> serviceInstances = discoveryClient.getInstances(s);
            System.out.println("serviceInstances.size():"+serviceInstances.size());
            for (ServiceInstance si: serviceInstances) {
                System.out.println(" service:" + s + ",getHost()="+si.getHost());
                System.out.println(" service:" + s + ",getServiceId()="+si.getServiceId());
                System.out.println(" service:" + s + ",si.getPort()"+si.getPort());
                System.out.println(" service " + s + ",getUri()"+si.getUri());
            }
        }
        Integer s = a + b;
        System.out.println("sum:" + s);
        return  s;
    }

}
